<?php	
	defined('_JEXEC') or die('Restricted access');
	//
	require_once("query_repository_class.php");
	require_once("base_tag_class.php");
	require_once("base_display_component_class.php");
    require_once("content_loader_class.php");
	require_once(CUTEENGINE_NAMESPACES_PATH."url_parameters_namespace.php");
    require_once(CUTEENGINE_NAMESPACES_PATH."javascript_namespace.php");
	require_once(CUTEENGINE_BASE_ACTION_PATH."base_action_class.php");
    
    //
	// t_cuteengine_component
	//
	class t_cuteengine_component
	{ 
        // property declaration
        // public
		public $log_fast ='';	
        // C
		public $current_url_parameter = false; // t_url_parameter
        //L
        public $log = false; //t_log

		// M
        public $main_url_arguments_array = array();
        public $main_url_methods_array = array();
		public $main_url_parameter = false; // t_url_parameter

        // Main db parameters
		public $main_query_parameter = false; // t_query_parameter
			
			const main_query_parameter_name = "main_query_parameter_array";        
			// table name field
			const main_query_field_name_class_module = "TipoComponente";
			const main_query_field_name_cuteengine_instances = "cuteengine_instances";
			const main_query_field_name_enabled = "enabled";
			const main_query_field_name_id = "ID";
			const main_query_field_name_common_parameters = "parametri_comuni";
			const main_query_field_name_specific_parameters = "parametri_specifici";
			const main_query_field_name_parent_component_id = "parent_component_id";
			const main_query_field_name_more_actions = "more_actions";
			const main_query_field_name_more_fields = "more_fields";
			const main_query_field_name_to_login = "to_login";
			const main_query_field_name_show_on_page = "show_on_page";
			const main_query_field_name_part_id = "part_id";
			const main_query_field_name_part_order = "part_order";
			const main_query_field_name_component_id = "component_id";
			const main_query_field_name_part_type = "part_type"; 
			const main_query_field_name_part_common_parameters = "part_common_parameters"; 	
			const main_query_field_name_part_specific_parameters = "part_specific_parameters";
			const main_query_field_name_part_specific_fields = "part_specific_fields"; 
			const main_query_field_name_part_required_actions = "part_required_actions"; 
			const main_query_field_name_part_enabled = "part_enabled"; 
			
			// db component parameter name
			const main_query_component_class_module = "TipoComponente";
          //  const main_query_component_components = "components";
			const main_query_component_enabled = "enabled";
			const main_query_component_id = "ID";
			const main_query_component_name = "name";
			const main_query_delays_the_creation_of_javascript = "delays_the_creation_of_javascript";
			const main_query_childs_components ='childs_components';
			const main_query_component_optimize_javascript_code = "main_query_component_optimize_javascript_code";
			const main_query_component_parent_id = "parent_id";
            const main_query_component_refresh_page_structure = "refresh_page_structure";
			const main_query_component_more_actions = "more_actions";
			const main_query_component_more_fields = "more_fields";
			const main_query_component_to_login = "to_login";
			const main_query_component_show_on_page = "show_on_page";
            
			//const main_query_component_stylesheet = "main_query_component_stylesheet";
			//const main_query_component_stylesheet_on_edit_page = "main_query_component_stylesheet_on_edit_page";


            // db component parameter position
            const main_query_parameter_position_part_id = 0;
            const main_query_parameter_position_order = 0;
            const main_query_parameter_position_part_type = 0;
			const main_query_parameter_position_component_id = 0;
			const main_query_parameter_position_part_common_parameters = -1;					
			const main_query_parameter_position_part_specific_parameters = -1;
			const main_query_parameter_position_part_specific_fields = -1;		
			const main_query_parameter_position_part_required_actions = -1;
			const main_query_parameter_position_part_enabled = 0;
            
        // P
        public $page_component = false; // an extension of t_base_component
		// Q
		public $query_repository = false; //t_query_repository
		//U
		public $user = null;
        
        // method declaration
		// private

        // I
        private function import_data_from_values_array($a_values_array)
        {
            $this->main_query_parameter->import_data_from_values_array($a_values_array);
        }

        // public
		public function __construct($a_url_parameter) 
		{
            global $g_database_namespace;
            global $g_cuteengine;
			global $g_ambient_namespace;
			
            // LOG
            $this->log = $g_ambient_namespace->log;
			// URL
			$this->set_url_parameter($a_url_parameter);
           // echo "component_id: ".$this->main_url_parameter->component_id . 
			//	" - method: ". $this->main_url_parameter->method."<br>";			
            
			//echo $g_database_namespace->main_table_name;
            /* 
                               main_query_parameter of CEC: 
                               it is used to retrieve data from database for the components that are called from url and 
                               they having in the main table of database the show_on_page field value set to zero 
                           */
			$local_sql = "SELECT * FROM ". $g_database_namespace->main_table_name . 
                //" LEFT JOIN `".$g_database_namespace->parts_table_name."` ON ID = component_id ".
                " WHERE (". self::main_query_component_id ." = ".$this->main_url_parameter->component_id.") and (".
				self::main_query_field_name_enabled ." = 1) and (". 
				t_cuteengine_component::main_query_field_name_cuteengine_instances ." LIKE '%@". $g_database_namespace->cuteengine_instance ."@%') 
                ORDER BY `ComponentOrder`";// , `part_order`";
			//echo $local_sql.'<br>';
			$this->query_repository = new t_query_repository;
			$this->query_repository->new_query(
				self::main_query_parameter_name,$local_sql,$g_ambient_namespace->connection);
			// COMPONENT ID
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_component_id,
				self::main_query_field_name_id,
				0);	
			// CLASS MODULE
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_class_module,
				self::main_query_field_name_class_module,
				0);					
			// PARENT ID
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_component_parent_id,
				self::main_query_field_name_parent_component_id,
				0);	
			// ENABLED	
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_component_enabled,
				self::main_query_field_name_enabled,
				0);
			// NAME	
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_component_name,
				self::main_query_field_name_common_parameters,
				1);	  
			//  delays_the_creation_of_javascript	
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_delays_the_creation_of_javascript,
				self::main_query_field_name_common_parameters,
				2);
			// childs_components	
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_childs_components,
				self::main_query_field_name_common_parameters,
				3);				
			// PART ENABLED	
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_part_enabled,
				self::main_query_field_name_part_enabled,
				1);	

            // PART TABLE    
			// PART ID
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_part_id,
				self::main_query_field_name_part_id,
				self::main_query_parameter_position_part_id);	
			// PART ORDER
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_part_order,
				self::main_query_field_name_part_order,
				self::main_query_parameter_position_order);	
			// COMPONENT ID
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_component_id,
				self::main_query_field_name_component_id,
				self::main_query_parameter_position_component_id);	
			// PART TYPE
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_part_type,
				self::main_query_field_name_part_type,
				self::main_query_parameter_position_part_type);	
			// PART COMMON PARAMETERS	
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_part_common_parameters,
				self::main_query_field_name_part_common_parameters,
				self::main_query_parameter_position_part_common_parameters);					
			// PART SPECIFIC PARAMETERS	
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_part_specific_parameters,
				self::main_query_field_name_part_specific_parameters,
				self::main_query_parameter_position_part_specific_parameters);		
			// PART SPECIFIC FIELDS	
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_part_specific_fields,
				self::main_query_field_name_part_specific_fields,
				self::main_query_parameter_position_part_specific_fields);				
			// PART REQUIRED ACTIONS
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_part_required_actions,
				self::main_query_field_name_part_required_actions,
				self::main_query_parameter_position_part_required_actions);			
			// PART ENABLED	
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_field_name_part_enabled,
				self::main_query_field_name_part_enabled,
				self::main_query_parameter_position_part_enabled);					
		

            // more_actions	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_more_actions,
				t_cuteengine_component::main_query_field_name_more_actions,
				-1);				
            // more_fields	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_more_fields,
				t_cuteengine_component::main_query_field_name_more_fields,
				-1);		
            // to_login	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_to_login,
				t_cuteengine_component::main_query_field_name_to_login,
				-1);				
            // show_on_page	
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_component_show_on_page,
				self::main_query_field_name_show_on_page,
				0);	
				
			// STYLESHEET	
			/*$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_component_stylesheet,
				self::main_query_field_name_specific_parameters,
				2);	 
			// STYLESHEET ON EDIT PAGE
			$this->query_repository->new_query_parameter(
				self::main_query_parameter_name,
				self::main_query_component_stylesheet_on_edit_page,
				self::main_query_field_name_specific_parameters,
				3);	 */				
			// MAIN DB QUERY
			$this->main_query_parameter = $this->query_repository->get_query(self::main_query_parameter_name);
            //echo "component_id: ".$this->main_url_parameter->component_id . " - method: ". $this->main_url_parameter->method."<br>";
           
		}
           
        // C
		/**********
			create_component()
			
			Create $page_component of type readed from db
			
		**********/
        public function create_component($a_query_parameter = null)
        {
            $local_skip_fetch = false;
			//
			global $g_ambient_namespace;
			
			if (!isset($a_query_parameter))
            {
                //echo "retrive_data_from_db"; 
				$this->retrive_data_from_db();
                $local_query_parameter = $this->main_query_parameter;
				
            }    
            else
            {
			   $local_query_parameter = $a_query_parameter;
               $this->import_data_from_values_array($local_query_parameter->sql_values);
			   
            }
            $local_component_id = $this->get_main_query_parameter_value(self::main_query_component_id);
			$local_class_module = $this->get_main_query_parameter_value(self::main_query_component_class_module);
            
			if ((trim($local_component_id) != '') && (trim($local_class_module) != ''))
            {
                //echo "local_component_id: $local_component_id";
				//echo "creo la classe <br>";
                //ob_start();
                try
                {
                    $g_ambient_namespace->autoload_content = 'components_content';
                    
					$this->page_component = new $local_class_module($this,$local_query_parameter);
					
 					//echo "get_parent_class: ". get_parent_class($this->page_component)."<br>";
                    $local_skip_fetch = (get_parent_class($this->page_component) == t_base_display_component);
                }
                catch (Exception $e) 
                {
                   // echo "error: $e->getMessage()<br>";
					$this->log->add_log_error($e->getMessage());
                }
                //echo "classe CREATA OK<br>";
                //ob_end_clean();
                //echo "local_component_id: $local_component_id";
                //echo "local_class_module: $local_class_module";
                
            }
            else            
            {
               // echo "The t_cuteengine_component was not found. ID: ".$this->main_url_parameter->component_id.". local_class_module: $local_class_module <br>";
				$this->log->add_log_error("The t_cuteengine_component was not found. ID: ".$this->main_url_parameter->component_id.". local_class_module: $local_class_module <br>");
            }
            return $local_skip_fetch;
        }
		// D
        public function disconnect_all_db_connections($a_ignore_mysql_close = false)        
        {
            //
			
			$this->query_repository->disconnect_all_db_connections($a_ignore_mysql_close);
		}	
		public function finalize_creation_component()
		{
            $this->page_component->finalize_creation_component();
        }
	
		// E
		public function execute_component_action()
		{
            try
            {
               // echo "execute_component_action " . $this->page_component->name ."<br>";
                $this->page_component->execute_component_action();
            }    
            catch (Exception $e) 
            {
                $this->log->add_log_error($e->getMessage());
            }                
		}
        // G
        public function generate_html_code($a_child_str_to_include = '')
        { 
            $local_result = '';
            try
            {       
                //echo "a_child_str_to_include: $a_child_str_to_include";
                //echo "generate_html_code prima<br>";
                $local_result = $this->page_component->generate_html_code($a_child_str_to_include);
                //echo "generate_html_code local_result:'$local_result'<br>";
            }    
            catch (Exception $e) 
            {
                $this->log->add_log_error($e->getMessage());
            }             
            return $local_result;
        }
        //
        public function generate_component_scripts(&$a_style_sheet_destination,
			&$a_javascript_functions_destination)
        { 
            $local_result = '';
            try
            {       
               // echo "a_child_str_to_include: $a_child_str_to_include";
                //echo "generate_html_code prima<br>";
                $this->page_component->generate_component_scripts($a_style_sheet_destination,
					$a_javascript_functions_destination);
                //echo "generate_html_code local_result:'$local_result'<br>";
            }    
            catch (Exception $e) 
            {
                //echo "ERRORE $e->getMessage()";
                $this->log->add_log_error($e->getMessage());
            }             
            
        }   
		public function generate_style_sheet_script(&$a_destination)
        { 
            
            try
            {       
               // echo "a_child_str_to_include: $a_child_str_to_include";
                //echo "generate_html_code prima<br>";
                $this->page_component->generate_style_sheet_script($a_destination);
                //echo "generate_html_code local_result:'$local_result'<br>";
            }    
            catch (Exception $e) 
            {
                //echo "ERRORE $e->getMessage()";
                $this->log->add_log_error($e->getMessage());
            }             
            
        }        
       /* public function generate_functions_script(&$a_destination)
        { 
            try
            {       
                $this->page_component->generate_functions_script($a_destination);
                //echo "generate_html_code local_result:'$local_result'<br>";
            }    
            catch (Exception $e) 
            {
                echo "ERRORE $e->getMessage()";
                $this->log->add_log_error($e->getMessage());
            }             
            
        } */
		// N
		public function new_url_argument($a_argument_name,$a_argument_position_of_value)
		{
			$this->main_url_arguments_array[$a_argument_name] = $a_argument_position_of_value;
        }    
		public function new_url_method($a_method_name,$a_method_label)
		{
        /*
                           It associates the name of the method(a_method_name) belonging to the current class to a label(a_method_label) which will be usable in the url parameter m(e.g.: m=create) in case you want to call this method
                  */
			$this->main_url_methods_array[$a_method_label] = $a_method_name;
        }
        // M
        public function main_query_field($a_query_field)
        {
			return $this->query_repository->query_field(self::main_query_parameter_name,
			  $a_query_field);
        }
        public function get_main_query_parameter_value($a_component_param)
        {
            return $this->query_repository->query_param(self::main_query_parameter_name,
			  $a_component_param);
        }
        // P
		public function prepare_scripts()
		{
            try
            {
                if (method_exists($this->page_component,'prepare_scripts'))
					$this->page_component->prepare_scripts();
            }    
            catch (Exception $e) 
            {
                $this->log->add_log_error($e->getMessage());
            }                
		}        

        // R
        public function retrive_data_from_db()
        {
            //$this->main_query_parameter->open_connection();
            try
            {
				$this->main_query_parameter->execute_query();
				$this->main_query_parameter->first();
            }    
            catch(Exception $e)
            {
                $this->log->add_log_error($e);    
            }   
            //$this->main_query_parameter->close_connection();
        }
		// S
		public function set_current_url_parameter($a_current_url_parameter)
        {
			$this->current_url_parameter = $a_current_url_parameter;
		}
        public function set_header_property_to_page($a_style_sheet_script,$a_include_link = true)
        {
            global $g_url_parameters_namespace;
            try
            {
                //echo "a_style_sheet_script: $a_style_sheet_script<br>";
                $local_parameter = $g_url_parameters_namespace->get_parameter_by_position(0);
               /* if ($local_parameter->request_type == t_url_parameter::request_type_new_page_old_session)
                    $this->page_component->reset_head_content();*/
                if ($a_include_link == true)
                    $this->page_component->include_external_link_text_script();
                else
                    $this->page_component->set_external_link_script();                
                    
                $this->page_component->set_style_sheet_script($a_style_sheet_script);
            }
            catch (Exception $e) 
            {
                //echo echo "<BR>" . __METHOD__ . "ERRORE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: ".$e->getMessage()."<BR>";
                $this->log->add_log_error($e);
            }                
        }
        public function set_javascript_functions_to_page($a_javascript_functions_script)
        {
            try
            {
                $this->page_component->set_javascript_functions_script($a_javascript_functions_script);
            }
            catch (Exception $e) 
            {
               // echo "<BR>" . __METHOD__ . "ERRORE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: ".$e->getMessage()."<BR>";
                $this->log->add_log_error($e);
            }                
        } 
        public function set_url_parameter($a_url_parameter)
        {
            try
            {
                $this->main_url_parameter = $a_url_parameter;
				$this->current_url_parameter = $a_url_parameter;
            }
            catch (Exception $e) 
            {
                $this->log->add_log_error($e->getMessage());
            }                
        }
        // U
        public function url_argument($a_url_argument)
        {
            //print_r($this->current_url_parameter);
			$a_url_argument_position = $this->main_url_arguments_array[$a_url_argument];
            return $this->current_url_parameter->get_argument_value(
				$a_url_argument_position);
        }
        public function url_method()
        {
            return $this->current_url_parameter->get_method_value();
        }        
    }
	//
	// t_cuteengine
	//
	class t_cuteengine
	{
	    public $log_fast ='';
		// property declaration
        //private
        // F
		private $finally_CECs = array();
		//  T
        private $temporary_processed_component_list = array();
        
        // public
		// A
		public $actions_list = array();
        // C
        public $components = array();
            const components_cuteengine_component = 'cuteengine_component';
            const components_query_values = 'components_query_values';
        public $content_loader = null; //t_content_loader;    
        public $current_language = '';
		public $current_session = '';
		// F
		public $fields_list = array();
		// E
		//public $edit_mode = false;
		public $enabled = false;
        public $error_message_sent = 0;
		// L
		public $login_field = null;
		//M
		public $max_error_message_sent = 15;
		

        // I
        public $id = false;
        // J
        const javascript_instance_name = 'window.cuteengine';
		// M
		public $main_query_parameter = false;  //t_query_parameter
        const main_query_component_language = "language";
        // O
        public $optimize_javascript_code = false;
		// Q
		public $query_repository = false; //t_query_repository
        // P
        public $page_structure_array = array(array(array()));// [level_no][parent_id][index] = component_id;
		public $parent_page_url = '';
        // R
        public $refresh_page_structure = false;
        // S
        const show_on_page_always_structure = 0;
        const show_on_page_always_without_sole_component = 1;
        const show_on_page_only_if_edit = 3;
        const show_on_page_only_if_requested = 2;
        const show_on_page_only_if_requested_and_sole_component = 4;
		const show_on_page_only_home_page = 5;
        public $sole_component_id = null;
        //
		public $site_name = '';
		// T
		public $timer = null;
		const timer_name = 'main_process_timer';
        // U
        public $url_parameters_list = false; // t_url_parameters_list;
        // method declaration
		// private
        // A
		private function add_finally_CECs()
		{
			//$this->add_component_to_page_structure(153);
			foreach ($this->finally_CECs as $local_CEC_id) 
			{
				$this->add_component_to_page_structure($local_CEC_id);
			}
			
		}
		private function add_javascript_initialization_component_on_onload_event()
		{
           	global $g_javascript_namespace;
			global $g_ambient_namespace;
            $this->log->initialize_javascript_function();
            //
            $local_this_constructor_prototype = 
				t_header_script_generator::this_constructor_prototype(null);
            //
            $g_javascript_namespace->header_script_generator->add_class(
				't_ce_extension','a_parent_tag','');
            $g_javascript_namespace->header_script_generator->add_property_to_a_class(
				't_ce_extension','changed_style','{}');                
            $g_javascript_namespace->header_script_generator->add_property_to_a_class(
				't_ce_extension','parent_tag','a_parent_tag');                
            $g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                't_ce_extension','change_style','a_property,a_value',"
            ".$local_this_constructor_prototype.".changed_style[a_property] = a_value;
            ".$local_this_constructor_prototype.".parent_tag.style[a_property] = a_value");    
            // t_cuteengine class
            $g_javascript_namespace->header_script_generator->add_class(
				get_class($this),'',t_base_display_component::base_javascript_component_name());            
            $g_javascript_namespace->header_script_generator->add_property_to_a_class(
				get_class($this),'delayed_scripts','[]'); 
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
				get_class($this),'browser',$g_ambient_namespace->user_agent->browser); 
            $g_javascript_namespace->header_script_generator->add_cuteengine_component_as_property_of_a_class(
                t_content_loader,"content_loader",get_class($this),$this->name,'','0');
			
    
			// method
            // A
            $local_parameters_list = new t_url_parameters_list(false);
            $local_parameters_list->add_new_parameter(
                $this->id,'add_log',
                "@'+hide_separator(a_msg_type)+'@'+hide_separator(local_msg)+'@'+hide_separator(local_url)+'@'+local_lno+'@'+hide_separator(getstack(e))+'@",
                t_url_parameter::request_type_no_page);
            
            $g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                get_class($this),'add_log',"a_msg_type,e,a_msg,a_url,a_lno","	
        if ((a_msg == undefined) && (e == undefined))
            local_msg = 'nessun messaggio';
        else if (e != undefined)   
            if (a_msg == undefined)
				local_msg = e.message;
			else
				local_msg = a_msg + ': ' + e.message;			
        else
            local_msg = a_msg;
        //	
        if ((a_lno == undefined) && (e == undefined))
            local_lno = '-1';
        else if (e != undefined)
            local_lno = e.lineNumber;
        else
            local_lno = a_lno;
        //	
        if ((a_url == undefined) && (e == undefined))
            local_url = 'nessun url';
        else if (e != undefined)
            local_url = e.fileName;
        else
            local_url = a_url;	
        
		". $this->content_loader->add_execute_javascript_code('this.content_loader',
            $local_parameters_list,'true',
			"'POST'",'undefined')." 
		");
		$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                get_class($this),'add_err_log',"e,a_msg,a_url,a_lno","	
        this.add_log(".t_log::msg_type_error.",e,a_msg,a_url,a_lno);
        ");
			$g_javascript_namespace->header_script_generator->add_content_to_a_method(
				get_class($this),t_header_script_generator::create_label,"
		".t_cuteengine::javascript_instance_name." = this");
			// G
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                get_class($this),'get_event_function',"a_this,a_function_name,a_position,a_function_arg","
		if (this.delayed_scripts[a_position] == undefined)
		{
			this.delayed_scripts[a_position] = 'loading'
		}
		var args = []; 		
		for(var i = 1; i<arguments.length; i++) 
			args.push(arguments[i]); 
			
			");
			// R
            $g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                get_class($this),'retrive_javascript_function','',"
        var result = true;
		if (this.delayed_scripts[a_position] == undefined)
		{
			this.delayed_scripts[a_position] = 'loading'
			result = false;
		} 
		if (result)
		{
            clearInterval(this.timer_retrive_javascript_function);
            return;
        }
        else
        {
                
        }");
            // S
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                get_class($this),'start_retrive_javascript_function','',"
        if (this.timer_retrive_javascript_function === null) 
        { 
            this.timer_retrive_javascript_function = setInterval ('this.retrive_javascript_function()', 100);
        }");
			//main scope
            $g_javascript_namespace->header_script_generator->add_function_to_main_scope(
                "init_cuteengine","","
            ".t_cuteengine::javascript_instance_name." = new ".get_class($this).
                t_header_script_generator::javascript_class_postfix()."();");
            //$g_javascript_namespace->add_body_event("onLoad","init_cuteengine()",false,'',
				//true,true);
           	/*if ($this->optimize_javascript_code === true)
            {
                $g_javascript_namespace->add_content_to_body_event("onLoad",
                    "init_" . get_class($this) . "= new Function(t_cuteengine::javascript_instance_name.' = {}');");
            }
            else
            {
                $g_javascript_namespace->header_script_generator->add_javascript_function(
                    "init_" . get_class($this)."()","\n".t_cuteengine::javascript_instance_name." = {};\n");
               
                    
            }        
			*/
                
        //$g_javascript_namespace->header_script_generator->add_content_to_javascript_object_method("window",
		//	"init_cuteengine()","\n".t_cuteengine::javascript_instance_name." = {};\n");                
       // $g_javascript_namespace->add_execution_of_javascript_object_method_to_body_event("onLoad",
		//	"window","".t_cuteengine::javascript_instance_name." = {}");
		}
		public function add_timer($a_autostart,$a_interval,$a_interval_first = -1)    
        {
			//echo "a_autostart: $a_autostart<br>";
			if (! isset($this->timer))
				$this->timer = new t_html_timer(self::timer_name,
					$a_autostart,$a_interval,$a_interval_first);
			return $this->timer;		
		}
        // C
        private function compute_page_structure()        
        {
        /*
			Clears and creates the entire structure of the page
		*/
			unset($this->page_structure_array);
            unset($this->temporary_processed_component_list);
            
            //
            foreach ($this->components as $local_component) 
			{
				//echo "local_component_id: $local_component_id<br>";
				$local_component_id = $local_component[self::components_query_values]
					[t_cuteengine_component::main_query_component_id];
				$this->set_page_structure($local_component_id);
			}
            //print_r($this->temporary_processed_component_list);
            //echo "<br>";
            //ksort($this->page_structure_array);
            //print_r($this->page_structure_array);
            //echo "<br>";
        }
        // D 
        private function display_component($a_component_id,$a_component_level)
        {   
            $local_result = '';
            $local_total_childs = '';
            //echo "<BR> a_component_id: $a_component_id - a_component_level: $a_component_level <br>";
            $local_next_level_no = $a_component_level+1;
            $local_next_level = $this->page_structure_array[$local_next_level_no];
            $local_component_childs_array = $local_next_level[$a_component_id];
            if (isset($local_component_childs_array))
            {
                foreach ($local_component_childs_array as $local_child_id) 
                {
                    $local_childs = $this->display_component($local_child_id,$local_next_level_no);
                    $local_total_childs .= $local_childs;
                    //echo "local_childs id $local_child_id: $local_childs<BR>";       
                    //echo "local_total_childs component_id $a_component_id: $local_total_childs<BR>";  
                }    
            }
            else
            {
               // echo "NO CHILDS<BR>";
            }
            //
            $local_page_component = $this->components[$a_component_id]
                    [self::components_cuteengine_component];
            //echo "local_childs TOTALI: $local_childs<BR>";       
            $local_result = $local_page_component->generate_html_code($local_total_childs);
            //
            return $local_result;  
        }
        
        // F
		private function finalize_creation_components()
		{
			global $g_javascript_namespace;
			foreach ($this->components as $local_component_id => $local_component) 
            {
                //echo "local_component_id: $local_component_id<br>";
				if ($local_component_id != '')
				{
					$local_site_component = $local_component[self::components_cuteengine_component];
					$local_site_component->finalize_creation_component();
				}	
            }
			if (isset($this->timer))
			{
				$local_content = $g_javascript_namespace->header_script_generator->add_cuteengine_component_as_property_of_a_class(
					t_html_timer,self::timer_name,get_class($this),$this->name,'','0',"[],".$this->timer->autostart.",".$this->timer->interval.
					",".$this->timer->interval_first.",'".$this->timer->get_js_component_array()."'");	
				$g_javascript_namespace->header_script_generator->move_method_content(get_class($this),
					t_header_script_generator::create_label,$local_content, 0);	
			}		
        }
		
		// I
		private function initialize_actions_list()
		{
            //global $g_cuteengine->actions_list;
			$local_levels_array = array();
			foreach ($this->actions_list as $local_action_name => $local_action)
			{
				//echo "Initialize level local_action_name:$local_action_name - ";
                $index_level = 1000-$local_action->level;
				//echo "local_action->level: ".$local_action->level." - index_level: ".$index_level."<br>";
				$local_levels_array[$index_level][] = $local_action;
			}
			//
			//print_r($local_levels_array);
			ksort($local_levels_array);
			//print_r($local_levels_array);
			foreach ($local_levels_array as $local_level_num => $local_level_array)
			{
				//echo "local_level_num: ".$local_level_num." - count: ".count($local_level_array)."<br> ";
				foreach ($local_level_array as $local_action)
				{
					//echo "Initializing... local_action->name:".$local_action->get_action_name()." <BR>";
                    $local_action->initialize();
                    //echo "Initialize local_action->name:".$local_action->get_action_name()."OK <BR>";
				}
                
			}	
				
			
        }		
        // G
        private function get_scripts_site_component($a_component_id,$a_component_level,
			&$a_style_sheet_destination,&$a_javascript_functions_destination)
        {   
            //$local_result = '';
            //echo "<BR> a_component_id: $a_component_id - a_component_level: $a_component_level <br>";
            $local_next_level_no = $a_component_level+1;
            $local_next_level = $this->page_structure_array[$local_next_level_no];
            $local_component_childs_array = $local_next_level[$a_component_id];
            //
            $local_page_component = $this->components[$a_component_id]
                [self::components_cuteengine_component];	
            if (get_parent_class($local_page_component) != 't_base_component')
				$local_page_component->generate_component_scripts($a_style_sheet_destination,
					$a_javascript_functions_destination);

            if (isset($local_component_childs_array))
            {
                foreach ($local_component_childs_array as $local_child_id) 
                {
                    $this->get_scripts_site_component($local_child_id,$local_next_level_no,
						$a_style_sheet_destination,	$a_javascript_functions_destination);
                    //$local_result .= $local_childs;
                    //echo "local_childs id $local_child_id: $local_childs<BR>";       
                    //echo "local_result component_id $a_component_id: $local_result<BR>";  
                }    
            }
            else
            {
               // echo "NO CHILDS<BR>";
            }
            //
           // return $local_result;  
        }  		
        private function get_style_sheet_site_component($a_component_id,$a_component_level,
			&$a_destination)
        {   
            //$local_result = '';
            //echo "<BR> a_component_id: $a_component_id - a_component_level: $a_component_level <br>";
            $local_next_level_no = $a_component_level+1;
            $local_next_level = $this->page_structure_array[$local_next_level_no];
            $local_component_childs_array = $local_next_level[$a_component_id];
            //
            $local_page_component = $this->components[$a_component_id]
                [self::components_cuteengine_component];
            $local_page_component->generate_style_sheet_script($a_destination);

            if (isset($local_component_childs_array))
            {
                foreach ($local_component_childs_array as $local_child_id) 
                {
                    $this->get_style_sheet_site_component($local_child_id,$local_next_level_no,$a_destination);
                    //$local_result .= $local_childs;
                    //echo "local_childs id $local_child_id: $local_childs<BR>";       
                    //echo "local_result component_id $a_component_id: $local_result<BR>";  
                }    
            }
            else
            {
               // echo "NO CHILDS<BR>";
            }
            //
           // return $local_result;  
        } 
		//
		/*private function get_javascript_functions_site_component($a_component_id,$a_component_level,
			&$a_destination)
        {   
            //$local_result = '';
            //echo "<BR> a_component_id: $a_component_id - a_component_level: $a_component_level <br>";
            $local_next_level_no = $a_component_level+1;
            $local_next_level = $this->page_structure_array[$local_next_level_no];
            $local_component_childs_array = $local_next_level[$a_component_id];
            //
            $local_page_component = $this->components[$a_component_id]
                [self::components_cuteengine_component];
            $local_page_component->generate_functions_script($a_destination);

            if (isset($local_component_childs_array))
            {
                foreach ($local_component_childs_array as $local_child_id) 
                {
                    $this->get_javascript_functions_site_component($local_child_id,$local_next_level_no,$a_destination);
                    //$local_result .= $local_childs;
                    //echo "local_childs id $local_child_id: $local_childs<BR>";       
                    //echo "local_result component_id $a_component_id: $local_result<BR>";  
                }    
            }
            else
            {
               // echo "NO CHILDS<BR>";
            }
            //
            //return $local_result;  
        }  		*/
        // P
        private function prepare_site_component_scripts_for_display()
        {
            try
            {
                //echo __METHOD__;
                foreach ($this->components as $local_component) 
                {
                    $local_site_component = $local_component[self::components_cuteengine_component];
                    $local_site_component->prepare_scripts();
                }
            }
            catch (Exception $e) 
            {
                //echo "<BR>" . __METHOD__ . "ERRORE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: ".$e->getMessage()."<BR>";
                $this->log->add_log_error($e);
            } 

        }    

        // S 
        private function set_page_structure($a_component_id,$a_level_no = 100)
        {
        /*
                           Calls the creation of CEC(create_CEC) and returns the level of the $a_component_id on the current page structure						   
                  */
            global $g_url_parameters_namespace;
            $local_component = $this->components[$a_component_id];
			//echo "set_page_structure($a_component_id)<br>";
			if (! isset($local_component))
			{
                /*    */
				$local_url_component = $g_url_parameters_namespace->add_new_parameter($a_component_id);
				//print_r($local_url_component);
                $this->create_CEC($local_url_component);
				$local_component = $this->components[$a_component_id];
				//echo "NEW local_component $a_component_id: $a_component_id<br>";
				//$local_component[self::components_cuteengine_component]->execute_component_action();
				
			}
            //
			if ($this->temporary_processed_component_list[$a_component_id] != null)
			{
				//echo "gia calcolato: ".$this->temporary_processed_component_list[$a_component_id]."<br>";
                /*  Gets from the list of processed component the level of the $a_component_id on the current page structure  */
				return $this->temporary_processed_component_list[$a_component_id];
				
			}
			else 
			{
				//print_r($local_component[self::components_query_values]);
                $local_parent_id = $local_component[self::components_query_values]
					[t_cuteengine_component::main_query_field_name_parent_component_id];
                //echo "local_parent_id: $local_parent_id<br>";    
				//
				if (($local_parent_id != null) && ($local_parent_id != 0))
				{
					/*  parent control  */
                    $a_level_no = $this->set_page_structure($local_parent_id,$a_level_no-1)+1;
				}
				/*  sets the level no of the $a_component_id on the current page structure  */
				$this->page_structure_array[$a_level_no][$local_parent_id][] = $a_component_id;
                $this->temporary_processed_component_list[$a_component_id] = $a_level_no;
				return $a_level_no;
            }
                
        }
        // S
        
		// method declaration
		// public
		public function __construct() 
		{
		  global $g_ambient_namespace;
		  global $g_database_namespace;
          global $g_javascript_namespace;
		  global $g_url_parameters_namespace;
		  global $g_cuteengine;
          
		  $g_cuteengine = $this;
		  if (! isset($this->user))
		  {
			//echo "CREATE USER<br>";
			$this->user = new t_user;
		  }	
         // echo "t_cuteengine in costruzione <br>";

		  try
		  {
			$this->content_loader = new t_content_loader($g_javascript_namespace,$this);
   			$this->content_loader->initialize_parameter('undefined',
				'undefined','undefined','undefined',
				'undefined','undefined',false);			
			// LOG
			$this->log = $g_ambient_namespace->log;
			//$g_ambient_namespace->set_international_option('eng_usa');
			// URL
			$local_sole_component_condition = '';
			$local_only_home_page_condition = '';
			$this->url_parameters_list = $g_url_parameters_namespace;
            if (!$g_url_parameters_namespace->is_empty())
			{
				$local_parameter = $g_url_parameters_namespace->get_parameter_by_position(0); 
				$local_sole_component_condition = t_cuteengine_component::main_query_field_name_id ." = ".$local_parameter->component_id.") or (";
			}
			else
			{
				$local_only_home_page_condition = t_cuteengine_component::main_query_field_name_show_on_page  ." = ".self::show_on_page_only_home_page.") or (";
			}
     		// DB
			$this->query_repository = new t_query_repository;
			//echo $g_database_namespace->cuteengine_class; 
           
			$local_sql = 
				"SELECT * FROM ". $g_database_namespace->main_table_name . 
               // " LEFT JOIN `".$g_database_namespace->parts_table_name."` ON ID = component_id ".
                " WHERE ((". t_cuteengine_component::main_query_field_name_class_module ." = '". $g_database_namespace->cuteengine_class ."') or ((".
				t_cuteengine_component::main_query_field_name_class_module ." = 't_component_inspector') and (" .(int)$g_ambient_namespace->edit_mode ." = 1)) or ((".
				$local_sole_component_condition .
				$local_only_home_page_condition .
			    t_cuteengine_component::main_query_field_name_show_on_page ." = ".self::show_on_page_always_structure.") or (".
				$local_show_on_page = t_cuteengine_component::main_query_field_name_show_on_page ." = ".self::show_on_page_always_without_sole_component.") or ((".
				t_cuteengine_component::main_query_field_name_show_on_page ." = ".self::show_on_page_only_if_edit.") and (".
                (int)$g_ambient_namespace->edit_mode ." = 1))) and (".
				t_cuteengine_component::main_query_field_name_enabled ." = 1)) and (". 
				t_cuteengine_component::main_query_field_name_cuteengine_instances ." LIKE '%@". $g_database_namespace->cuteengine_instance ."@%') 
                ORDER BY `ComponentOrder`";//, `part_order`";
			//echo $local_sql ."<br>";	
			$this->query_repository->new_query(t_cuteengine_component::main_query_parameter_name,
				$local_sql,$g_ambient_namespace->connection);
            
            // main_query_parameter of CEC of t_cuteengine component
			// COMPONENT ID
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_id,
				t_cuteengine_component::main_query_field_name_id,
				0);	
			// CLASS MODULE
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_class_module,
				t_cuteengine_component::main_query_field_name_class_module,
				0);					
			// PARENT ID
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_parent_id,
				t_cuteengine_component::main_query_field_name_parent_component_id,
				0);	
			// ENABLED	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_enabled,
				t_cuteengine_component::main_query_field_name_enabled,
				0);	                
			// NAME	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_name,
				t_cuteengine_component::main_query_field_name_common_parameters,
				1);	



            // PART TABLE    
			// PART ID
			/*$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_id,
				t_cuteengine_component::main_query_field_name_part_id,
				t_cuteengine_component::main_query_parameter_position_part_id);	
			// PART ORDER
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_order,
				t_cuteengine_component::main_query_field_name_part_order,
				t_cuteengine_component::main_query_parameter_position_order);	
			// COMPONENT ID
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_component_id,
				t_cuteengine_component::main_query_field_name_component_id,
				0);	
			// PART TYPE
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_type,
				t_cuteengine_component::main_query_field_name_part_type,
				t_cuteengine_component::main_query_parameter_position_part_type);	
			// PART NAME	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_part_name,
				t_cuteengine_component::main_query_field_name_part_common_parameters,
				t_cuteengine_component::main_query_parameter_position_part_name);					
			// PARTs fields	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_part_fields,
				t_cuteengine_component::main_query_field_name_part_common_parameters,
				t_cuteengine_component::main_query_parameter_position_part_fields);		
			// PART ENABLED	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_enabled,
				t_cuteengine_component::main_query_field_name_part_enabled,
				t_cuteengine_component::main_query_parameter_position_part_enabled);*/
// PART ID
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_id,
				t_cuteengine_component::main_query_field_name_part_id,
				t_cuteengine_component::main_query_parameter_position_part_id);	
			// PART ORDER
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_order,
				t_cuteengine_component::main_query_field_name_part_order,
				t_cuteengine_component::main_query_parameter_position_order);	
			// COMPONENT ID
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_component_id,
				t_cuteengine_component::main_query_field_name_component_id,
				t_cuteengine_component::main_query_parameter_position_component_id);	
			// PART TYPE
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_type,
				t_cuteengine_component::main_query_field_name_part_type,
				t_cuteengine_component::main_query_parameter_position_part_type);	
			// PART COMMON PARAMETERS	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_common_parameters,
				t_cuteengine_component::main_query_field_name_part_common_parameters,
				t_cuteengine_component::main_query_parameter_position_part_common_parameters);					
			// PART SPECIFIC PARAMETERS	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_specific_parameters,
				t_cuteengine_component::main_query_field_name_part_specific_parameters,
				t_cuteengine_component::main_query_parameter_position_part_specific_parameters);		
			// PART SPECIFIC FIELDS	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_specific_fields,
				t_cuteengine_component::main_query_field_name_part_specific_fields,
				t_cuteengine_component::main_query_parameter_position_part_specific_fields);				
			// PART REQUIRED ACTIONS
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_required_actions,
				t_cuteengine_component::main_query_field_name_part_required_actions,
				t_cuteengine_component::main_query_parameter_position_part_required_actions);			
			// PART ENABLED	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_field_name_part_enabled,
				t_cuteengine_component::main_query_field_name_part_enabled,
				t_cuteengine_component::main_query_parameter_position_part_enabled);				
		
			
					
            // more_actions	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_more_actions,
				t_cuteengine_component::main_query_field_name_more_actions,
				-1);	
            // more_fields	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_more_fields,
				t_cuteengine_component::main_query_field_name_more_fields,
				-1);	            
			// to_login	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_to_login,
				t_cuteengine_component::main_query_field_name_to_login,
				-1);				
			// show_on_page	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_show_on_page,
				t_cuteengine_component::main_query_field_name_show_on_page,
				0);
			// LANGUAGE	
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				self::main_query_component_language,
				t_cuteengine_component::main_query_field_name_specific_parameters,
				1);                
			// STYLESHEET	
			/*$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_stylesheet,
				t_cuteengine_component::main_query_field_name_specific_parameters,
				2);	 
			// STYLESHEET ON EDIT PAGE
			$this->query_repository->new_query_parameter(
				t_cuteengine_component::main_query_parameter_name,
				t_cuteengine_component::main_query_component_stylesheet_on_edit_page,
				t_cuteengine_component::main_query_field_name_specific_parameters,
				3);	 	*/			
   
			// MAIN DB QUERY
			$this->main_query_parameter = $this->query_repository->get_query(t_cuteengine_component::main_query_parameter_name);
            $this->main_query_parameter->execute_query();
			$this->is_there_only_if_requested_and_sole_component();
           // $g_ambient_namespace->execute_autologon();
	
			$this->load_configuration_from_db();
				
			$this->add_finally_CECs();
				
            //echo "dopo di load config";
		  }    
          catch(Exception $e)
          {
            $this->log->add_log_error($e);    
          } 	
		}
		// A
		public function add_all_CEC()
		{
            $local_function = "add_new_CEC";
            $this->main_query_parameter->execute_function_from_query_result($this,$local_function);
			
		}
		public function add_CEC_into_finally_CECs($a_CEC_id)
		{
			//echo "a_CEC_id: $a_CEC_id<br>";
			$this->finally_CECs[] = $a_CEC_id;
		}	
        public function add_component_to_page_structure($a_component_id)        
        {
        /*
			Creates and adds the $a_component_id to the current page by calling the method set_page_structure
		*/   
		   // echo "Aggiungo '$a_component_id' <br>";
            $this->set_page_structure($a_component_id);
            //
            //print_r($this->temporary_processed_component_list);
            //echo "<br>";
            ksort($this->page_structure_array);
            //print_r($this->page_structure_array);
            //echo "<br>";
        }  
        
        public function add_log()    
        {
            global $g_url_parameters_namespace;
			global $g_ambient_namespace;
            $local_parameter = $g_url_parameters_namespace->get_parameter_by_position(0); 
            //print_r($local_parameter);
			$this->log->add_log_from_javascript(
                $g_ambient_namespace->remove_hide_separator($local_parameter->get_argument_value(1)),
                $g_ambient_namespace->remove_hide_separator($local_parameter->get_argument_value(2)),
                $g_ambient_namespace->remove_hide_separator($local_parameter->get_argument_value(3)),
                $g_ambient_namespace->remove_hide_separator($local_parameter->get_argument_value(4)),
                $g_ambient_namespace->remove_hide_separator($local_parameter->get_argument_value(5)));
        }
       	public function add_new_CEC($a_query_parameter,$a_current_row_no,$a_rows_count)
		{
            
			$local_result = false;
			//echo "a_rows_count: $a_rows_count<br>";
			if ($a_rows_count == 0)
				return local_result;
			global $g_ambient_namespace;
			global $g_database_namespace;
			global $g_javascript_namespace;
            global $g_url_parameters_namespace;
            
			//echo "this->sole_component_id: $this->sole_component_id<br>";
			//echo "ID: ". $a_query_parameter->sql_values[t_cuteengine_component::main_query_component_id] . " - show_on_page: ".$a_query_parameter->sql_values[t_cuteengine_component::main_query_component_show_on_page]." <br>";
			try
			{
				if ($a_query_parameter->sql_values[t_cuteengine_component::main_query_field_name_class_module] == $g_database_namespace->cuteengine_class)
				{
					//echo "START - add_new_CEC - cuteengine component<br>";
					$this->site_name = $this->query_repository->query_param(
						t_cuteengine_component::main_query_parameter_name,
						t_cuteengine_component::main_query_component_name);
					/*$local_components = $this->query_repository->query_param(
						t_cuteengine_component::main_query_parameter_name,
						t_cuteengine_component::main_query_component_components); 
					//echo "local_components: $local_components";
					$local_components_array = explode(
						t_query_parameter::separator_level_1,
						$local_components);                    */
					$this->enabled = $this->query_repository->query_param(
						t_cuteengine_component::main_query_parameter_name,
						t_cuteengine_component::main_query_component_enabled);
					$this->refresh_page_structure = $this->query_repository->query_param(
						t_cuteengine_component::main_query_parameter_name,
						t_cuteengine_component::main_query_component_refresh_page_structure);
					$this->optimize_javascript_code = $this->query_repository->query_param(
						t_cuteengine_component::main_query_parameter_name,
						t_cuteengine_component::main_query_component_optimize_javascript_code);
					$this->id = $this->query_repository->query_param(
						t_cuteengine_component::main_query_parameter_name,
						t_cuteengine_component::main_query_field_name_id);
					//
					$local_language = $this->query_repository->query_param(
						t_cuteengine_component::main_query_parameter_name,
						self::main_query_component_language);
					
					if ($local_language == '')
						echo "ERRORE!!!!!!!!!!!  local_language: $local_language<br>";
                    $this->current_language = $local_language;
					$g_ambient_namespace->set_international_option($local_language);
					$g_ambient_namespace->connection->set_time_zone();
					$g_ambient_namespace->connection->set_character_set();
						
					
					$this->add_javascript_initialization_component_on_onload_event();
					
                   // echo "END - add_new_CEC - cuteengine component<br>";
				}
				else if (($this->sole_component_id === null) || 
                    ($a_query_parameter->sql_values[t_cuteengine_component::main_query_component_show_on_page] != self::show_on_page_always_without_sole_component))
				{   
					
					//echo " - ". $a_query_parameter->sql_values[t_cuteengine_component::main_query_component_id] . "<br>";
					//echo "START - add_new_CEC - ";
					$local_component_id = $a_query_parameter->sql_values[t_cuteengine_component::main_query_component_id];
					//echo "local_component_id: $local_component_id <BR>";
					$local_url_component = $g_url_parameters_namespace->get_parameter_by_component_id($local_component_id);
					if (! isset($local_url_component))
					{
						//echo "local_component_id: $local_component_id - count: ".count($g_url_parameters_namespace->parameters_list);
						$local_url_component = $g_url_parameters_namespace->add_new_parameter($local_component_id);
						//echo "dopo local_component_id: $local_component_id - count: ".count($g_url_parameters_namespace->parameters_list);
					}	
					//echo "main_query_field_name_part_id: ".$this->main_query_parameter->sql_values[t_cuteengine_component::main_query_field_name_part_id] . "<BR>";
                   $local_result = $this->create_CEC($local_url_component,$this->main_query_parameter);
					//echo "local_component_id: $local_component_id - OK <BR>";
					 
					//echo "END - add_new_CEC - local_component_id: $local_component_id <BR>";
					$local_component_id = $a_query_parameter->sql_values[t_cuteengine_component::main_query_component_id];
				}
			}
			catch (Exception $e) 
            {
                //echo "<BR>" . __METHOD__ . "ERRORE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: ".$e->getMessage()."<BR>";
                $this->log->add_log_error($e);
            } 
            //echo "END add_new_CEC <BR>";
			
			return $local_result;
		}
        
        public static function create_cuteengine()    
        {
            global $g_url_parameters_namespace;
            global $g_ambient_namespace;
            global $g_cuteengine;
           // global $g_cuteengine->actions_list;
            global $g_javascript_namespace;
			//global $g_database_namespace;
			//$g_ambient_namespace->log->add_log_error("_SERVER['REQUEST_URI']".$_SERVER['REQUEST_URI']);
			
			
			// start_session
			$g_ambient_namespace->log->reset_report_log();
			$g_ambient_namespace->log->add_a_report_log("------>START ".__METHOD__);
            $g_ambient_namespace->start_session();
			$g_ambient_namespace->log->add_a_report_log("--->STARTED SESSION");
			$local_parameter = $g_url_parameters_namespace->get_parameter_by_position(0); 
			if ((! isset($local_parameter)) ||
				(($local_parameter->request_type == t_url_parameter::request_type_new_page)))
			{

				$last_session = session_id();
				//echo "NEW PAGE<br>";
				if (array_key_exists('g_cuteengine',$_SESSION))
                {
					$local_cuteengine = $_SESSION["g_cuteengine"];
					//echo "local_cuteengine->get_actions_list_count(): " . $local_cuteengine->get_actions_list_count() ."<br>";
					if ($local_cuteengine->get_actions_list_count() > 0)
					{
						/*foreach ($local_cuteengine->actions_list as $local_action_name => $local_action)
						{
							echo "local_action->get_action_name(): " . $local_action->get_action_name()."<br>";
						}*/
						session_regenerate_id();
					}	
				}					
							$local_parameter = $g_url_parameters_namespace->get_parameter_by_position(0); 
				//echo "LAST session_id: " . $last_session . "<br>";
				//echo "session_id: " . session_id() . "<br>";

			}
			else			
			{
				//echo "_POST" . $_POST['sid'] .'<br>';
				//echo "session_id: " . session_id() . "<br>";
				//echo "COOKIE: "; print_r($_COOKIE); echo "<br>";
			}
			
            //
			//print_r($g_ambient_namespace->cookie_request); echo "<br>";
			//echo $g_database_namespace->cuteengine_class;
               
            //
			if (isset($local_parameter) && ($local_parameter->request_type != t_url_parameter::request_type_no_page) && ($g_ambient_namespace->user_agent->browser != t_user_agent_component::t_browser_nn))
            {
                //$g_ambient_namespace->log->add_log_on_page("_SERVER['REQUEST_URI']: ".$_SERVER['REQUEST_URI']);            
                $g_ambient_namespace->log->add_log_normal("_SERVER['REQUEST_URI']: ".$_SERVER['REQUEST_URI']);
            }
           // echo "array_key_exists('g_cuteengine',_SESSION): " . array_key_exists('g_cuteengine',$_SESSION)."<br>";
            if ((array_key_exists('g_cuteengine',$_SESSION)) && 
                ((isset($local_parameter) && (
                ($local_parameter->request_type === t_url_parameter::request_type_no_page)/*||
                ($local_parameter->request_type === t_url_parameter::request_type_new_page_old_session)*/)))) 
            {
				//echo "g_cuteengine ALREADY EXISTS<br>";
               // echo "local_parameter->request_type: $local_parameter->request_type<br>";
				$g_cuteengine = $_SESSION["g_cuteengine"];
				
				$g_javascript_namespace = new t_javascript_namespace;               
				$g_ambient_namespace->log->add_a_report_log("--->USE OLD ");
                //echo "use OLD g_cuteengine<br>";
				$g_ambient_namespace->log->add_log_on_page("use OLD g_cuteengine");
                // International Options
				//print_r($g_ambient_namespace);
								
				if ($g_cuteengine->current_language == '')
				{
					//print_r($g_cuteengine);
					$g_cuteengine->log->add_log_error("language not specified.");
					$local_language = $g_cuteengine->query_repository->query_param(
						t_cuteengine_component::main_query_parameter_name,
						self::main_query_component_language);
					//echo "local_language: $local_language <br>";	
					$g_cuteengine->current_language = $local_language;	
					//echo "g_cuteengine->current_language: $g_cuteengine->current_language<br>";
				}		
                
				
				$g_ambient_namespace->set_international_option($g_cuteengine->current_language);
				$g_ambient_namespace->connection->set_time_zone();
				$g_ambient_namespace->connection->set_character_set();
                //
               //$g_javascript_namespace = $_SESSION["g_javascript_namespace"];
				
				$g_cuteengine->disconnect_component_db_connections($local_parameter->component_id,true);
				
				$g_ambient_namespace->open_db_connection();
				//echo "g_ambient_namespace->connection->connected:  " .$g_ambient_namespace->connection->connected ."<br>";
            }
            else
            {
				//echo "g_cuteengine DOES NOT EXISTS<br>";
                //echo "local_parameter->request_type: $local_parameter->request_type<br>";
				if (($local_parameter->request_type === t_url_parameter::request_type_no_page)/*||
					($local_parameter->request_type === t_url_parameter::request_type_new_page_old_session)*/)
                {
                    echo "TIME OUT, redirect....";
					if (isset($local_parameter))
                    {
                        $local_parameter->request_type = t_url_parameter::request_type_new_page;
                        $local_parameter->argument = '';
                        $local_parameter->method = null;
                    }
                    $local_result = new t_content_loader_result;                    
                    $local_result->error_msg = 'TIME OUT, redirect....';
                    $local_result->add_function_result(
						"","","",
						"window.location.replace('".str_replace("'", "\'",
						$g_ambient_namespace->get_absolute_web_file_path(true).$g_url_parameters_namespace->current_site/*.$g_url_parameters_namespace->compute_disguised_parameters_string()*/)."');");   
//                    echo $g_ambient_namespace->get_absolute_web_file_path(false).$g_url_parameters_namespace->compute_disguised_parameters_string();
                    echo $local_result->get_json_string();
                    exit;
                }    
				//echo "CREATE NEW g_cuteengine<br>";
                $g_ambient_namespace->log->add_a_report_log("--->CREATE NEW g_cuteengine");
                if (isset($local_parameter) && ($local_parameter->request_type !== t_url_parameter::request_type_no_page_no_session))
                    $local_parameter->request_type = t_url_parameter::request_type_new_page;
                $g_ambient_namespace->log->add_log_on_page("create NEW g_cuteengine");
				$g_ambient_namespace->open_db_connection();
				
				$g_javascript_namespace = new t_javascript_namespace;
				//print_r($g_javascript_namespace->header_script_generator->class_already_exist(''));
                //$_SESSION["g_javascript_namespace"] = $g_javascript_namespace;
				//
                $local_cuteengine = $_SESSION["g_cuteengine"];
			
				new t_cuteengine;
				
				$g_cuteengine->parent_page_url = "http://".$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"];
				//echo "local_cuteengine->user: "; print_r($local_cuteengine->user);
				if (isset($local_cuteengine->user))
					$g_cuteengine->user = $local_cuteengine->user;
				//echo "got user from _SESSION[\"g_cuteengine\"]<br>";
				//echo '4-count $_SESSION["g_cuteengine->actions_list"]: '.count($g_cuteengine->actions_list)."<br>";
                $_SESSION["g_cuteengine"] = $g_cuteengine;
				$g_cuteengine->set_current_session(session_id());
               // $_SESSION["g_cuteengine->actions_list"] = $g_cuteengine->actions_list;
	
            }
			//echo "g_cuteengine->parent_page_url: ".$g_cuteengine->parent_page_url."<br>";
            
        }    
        

        /***********
			create_CEC()

			Create a new t_cuteengine_component.
                           Add the new CEC into $this->components[a_component_id][self::components_cuteengine_component]
			Add a query values owned to the new CEC into $this->components[a_component_id][self::components_query_values]
			
		************/
		public function create_CEC($a_url_parameter,$a_query_parameter = null)
        {
            //echo "a_url_parameter: ";
            //print_r($a_url_parameter);
            //echo "<br>a_values_array: ";
            //print_r($a_values_array);
            //echo "<br>";
			
            $local_cuteengine_component = new t_cuteengine_component($a_url_parameter);

            //echo "new component OK <BR>";
			
			$local_skip_fetch = $local_cuteengine_component->create_component($a_query_parameter);

            //echo "create_component OK <BR>";
            $local_component_id = $local_cuteengine_component->page_component->id;
            //get_main_query_parameter_value(t_cuteengine_component::main_query_component_id);
            //print_r($local_cuteengine_component->main_query_parameter->sql_values);
            //echo "<br>";
            $this->components[$local_component_id][self::components_query_values] = 
                $local_cuteengine_component->main_query_parameter->sql_values;
            $this->components[$local_component_id][self::components_cuteengine_component] = $local_cuteengine_component;
			//echo "create_CEC OK <BR>";
			return $local_skip_fetch;
        }
        // D 
		private function do_action($a_action_name = null,$a_json_result = null)
        {
            global $g_url_parameters_namespace;
			global $g_ambient_namespace;
           // global $g_cuteengine->actions_list;
			if ($a_action_name == null)
			{
				$local_parameter = $g_url_parameters_namespace->get_parameter_by_position(0); 
				$local_action_name = $local_parameter->get_argument_value(1);
			}
			else
				$local_action_name = $a_action_name;
            //echo "local_action_name: $local_action_name<br>";
			//var_dump($this->actions_list);
            if (array_key_exists($local_action_name,$this->actions_list))
            {
               // echo "local_action_name: $local_action_name<br>";
				$local_action = $this->actions_list[$local_action_name];
				if ($local_action->is_executable())
				{
					//echo "ssss";
					if ($local_action->are_permissions_done())
						$local_action->do_action_from_ajax($a_json_result);
					else
						$g_ambient_namespace->log->add_log_error("try to execute actions '$local_action_name' without permission required");
				}
				else
					$g_ambient_namespace->log->add_log_error("try to execute actions '$local_action_name' that in the caller contest is not executable");
            }
            else
            {
                //echo "local_action_name: $local_action_name in the caller contest doesn't exist<br>";
                //var_dump($this->actions_list);
                $g_ambient_namespace->log->add_log_error("try to execute actions '$local_action_name' that in the caller contest doesn't exist");
                if (isset($local_parameter))
                {
                    $local_parameter->request_type = t_url_parameter::request_type_new_page;
                    $local_parameter->argument = '';
                    $local_parameter->method = null;
                }
                $local_result = new t_content_loader_result;                    
                $local_result->error_msg = 'ACTION NOT FOUND, redirect....';
                $local_result->add_function_result(
                    "","","",
                    "window.location.replace('".str_replace("'", "\'",
                    $g_ambient_namespace->get_absolute_web_file_path(true).$g_url_parameters_namespace->current_site/*.$g_url_parameters_namespace->compute_disguised_parameters_string()*/)."');");   
//                    echo $g_ambient_namespace->get_absolute_web_file_path(false).$g_url_parameters_namespace->compute_disguised_parameters_string();
                echo $local_result->get_json_string();
                exit;                
            }    
        }

        private function display_page()
        {   
            global $g_javascript_namespace;
            global $g_ambient_namespace;
            $g_ambient_namespace->log->add_a_report_log("------>START ".__METHOD__);
            try
            {
                //echo __METHOD__;
                //
                //echo "count this->page_structure_array:".count($this->page_structure_array)."<br>";
                $local_first_level = reset($this->page_structure_array);
                $local_first_level_no = key($this->page_structure_array);
                //echo "local_first_level_no:".$local_first_level_no."<br>";
                //echo "count local_first_level:".count($local_first_level)."<br>";
                $local_root_parent = reset($local_first_level);
                //echo "count local_root_parent:".count($local_root_parent)."<br>";
                $local_root_component_id = reset($local_root_parent);
               // echo "local_root_component_id:".$local_root_component_id."<br>";
                // style sheet
                $local_page_style_sheet = '';
                //
                $this->prepare_site_component_scripts_for_display();
                $local_page_javascript_functions = $g_javascript_namespace->generate_all_javascript_script();	;
                //
                
                $this->get_scripts_site_component($local_root_component_id,$local_first_level_no,
                    $local_page_style_sheet,$local_page_javascript_functions);
                
                //echo "local_page_style_sheet: $local_page_style_sheet<br>";
                // echo "local_page_javascript_functions: $local_page_javascript_functions";
                //echo "PRIMA set_header_property_to_page<br>";
                $this->set_header_property_to_page($local_root_component_id,$local_page_style_sheet);
               // echo "PRIMA set_javascript_functions_to_page<br>";
                $this->set_javascript_functions_to_page($local_root_component_id,$local_page_javascript_functions);
               // echo "PRIMA display_component<br>";
              // print_r($this->user);
			   $local_result = $this->display_component($local_root_component_id,$local_first_level_no);
               // echo "PRIMA echo local_result<br>";
			   $g_ambient_namespace->log->add_a_report_log("<--- BEFORE ECHO CONTENT");
                echo $local_result;

            }
            catch (Exception $e) 
            {
                //echo "<BR>" . __METHOD__ . "ERRORE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: ".$e->getMessage()."<BR>";
                $this->log->add_log_error($e);
            } 
            $g_ambient_namespace->log->add_a_report_log("<------STOP ".__METHOD__);    
        }
		
        public function disconnect_all_db_connections($a_ignore_mysql_close = false)        
        {
            //
			//echo "count: ".count($this->components);
            foreach ($this->components as $local_component) 
			{
				$local_site_component = $local_component[self::components_cuteengine_component];
				$local_site_component->disconnect_all_db_connections($a_ignore_mysql_close);
			}
		}
        public function disconnect_component_db_connections($a_id,$a_ignore_mysql_close = false)        
        {
            //
			if (array_key_exists($a_id,$this->components))
			{
				$local_site_component = $this->components[$a_id][self::components_cuteengine_component];
				$local_site_component->disconnect_all_db_connections($a_ignore_mysql_close);
			}
			$this->log->add_log_on_page("DISCONNESSE TUTTE LE CONNESSIONI APERTE");
		}
		
		
		// E
		public function execute()
		{
            //echo "ciao";
            global $g_url_parameters_namespace;
            global $g_ambient_namespace;
            $g_ambient_namespace->log->add_a_report_log("------>START ".__METHOD__);
            try
            {
                //echo __METHOD__;
                if ($this->enabled)
                {
                    $local_execute = true;
                    
                    $local_parameter = $g_url_parameters_namespace->get_parameter_by_position(0);
                   // echo "local_parameter->component_id: $local_parameter->component_id - this->id: $this->id<br>";
                    if (isset($local_parameter) && ($local_parameter->component_id == $this->id))
                    {
                        /* execute a t_cuteengine method */
                        try
                        {
                            
                            $local_method = $local_parameter->method;
                            //echo "local_method: $local_method<br>";
                            $g_ambient_namespace->log->add_log_on_page("component_id: ".$local_parameter->component_id." - method: " .$local_method);
                            $this->$local_method();
                            $local_execute = false;
                        }
                        catch (Exception $e) 
                        {
                            $this->log->add_log_error($e);
                        }      
                    }
                    //
                   // echo "local_execute: $local_execute <br>";
                    if ($local_execute === true)
                    {
                        //echo "Before execute <br>";
                        if (isset($local_parameter) && 
                            ($local_parameter->request_type == t_url_parameter::request_type_new_page))
                        {
                            //echo "$local_parameter->request_type <br>";
                            /* Clears and creates the entire structure of the page */
                            $this->compute_page_structure();
							/* process components method retrived from url */
							$this->initialize_url_components();
							/* initialize actions method retrived from url */
							$this->initialize_actions_list();
							$this->finalize_creation_components();
							//echo "$initialize_url_components OK <br>";
							
                        } 
						//
						foreach ($g_url_parameters_namespace->parameters_list as $local_url_param)
						{
							$g_ambient_namespace->log->add_log_on_page("local_url_param->component_id: $local_url_param->component_id");
							//echo "local_url_param->component_id: $local_url_param->component_id <br>";
							//echo "local_url_param->method: $local_url_param->method <br>";
							if (array_key_exists($local_url_param->component_id,$this->components))
							{
								$local_ce_component = $this->components[$local_url_param->component_id]
									[self::components_cuteengine_component];
								if (($local_parameter->request_type == t_url_parameter::request_type_no_page))
									$local_ce_component->set_current_url_parameter($local_url_param);
								$local_ce_component->execute_component_action();
							}		
						}
                        //
                        if (isset($local_parameter) && 
                            (($local_parameter->request_type == t_url_parameter::request_type_new_page)/* ||
                            ($local_parameter->request_type == t_url_parameter::request_type_new_page_old_session)*/))
                        {
                            //echo "display_page <br>";
                            $this->display_page();
                        }    
                    }    
                }
                else
                {
                    echo $this->generate_temporary_page_script("SITE ". $this->site_name ." MOMENTANEAMENTE NON DISPONIBILE");
                }
                $this->log->add_log_on_page("fine rederizzazione ");
                $g_ambient_namespace->close_db_connection();
            }
            catch (Exception $e) 
            {
                echo "<BR>" . __METHOD__ . " - ERRORE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: ".$e->getMessage()."<BR>";
                $this->log->add_log_error($e->getMessage());
            } 
			//global $g_cuteengine->actions_list;
		//	echo 'count $_SESSION["g_cuteengine->actions_list"]: '.count($this->actions_list)."<br>";
			//echo 'count g_cuteengine->actions_list: '.count($this->actions_list)."<br>";
			//echo "fine<br>";
            //while (@ob_end_flush());
			//echo "DOPO ob_end_flush<br>";
			$g_ambient_namespace->log->add_a_report_log("<------STOP ".__METHOD__);
            
		}
		public function execute_old()
		{
			global $g_url_parameters_namespace;
            foreach ($g_url_parameters_namespace->parameters_list as $local_url_param)
			{
				$this->create_CEC($local_url_param,$this->main_query_parameter);
				$this->components[$local_url_param->component_id][self::components_cuteengine_component]->execute_component_action();
			}
		}
		// G
		public function get_actions_list_count()
        {
			return count($this->actions_list);
		}	
		// I
		public function is_foundation_component($a_component_id)
        {
			//echo "is_foundation_component($a_component_id)<br>";
			$local_component = $this->components[$a_component_id];
			return ((isset($local_component)) && 
				($local_component_values[self::components_query_values]
				[t_cuteengine_component::main_query_component_show_on_page] == self::show_on_page_always_structure));
		}
		public function initialize_component($a_component_id,$a_url_param)
		{
           
            $local_component = $this->components[$a_component_id];
            //echo "local_component->id:$local_component.id";
            if ((! isset($local_component)) || (! array_key_exists(self::components_cuteengine_component,$local_component)))
            {
                //echo __METHOD__."<br>";
                $this->create_CEC($a_url_param);
            } 
            else
            {
                $this->set_url_parameter($a_component_id,$a_url_param);
            }
        }
		public function initialize_url_components()
		{
		/*
            Calls the initialize_component method for every component specify in the url parameters
        */	
			global $g_url_parameters_namespace;
            foreach ($g_url_parameters_namespace->parameters_list as $local_url_param)
			{
                //var_dump($local_url_param); 
                $this->initialize_component($local_url_param->component_id,$local_url_param);
			}
		} 		
		public function is_there_only_if_requested_and_sole_component()
        {
            global $g_url_parameters_namespace;
            
            if ($this->sole_component_id === null)
            {
                $local_parameter = $g_url_parameters_namespace->get_parameter_by_position(0); 
                if (isset($local_parameter))
                {
                    //echo "omponent_id: ".$local_parameter->component_id."<br>";
                    $local_index = $this->main_query_parameter->locate(
                        t_cuteengine_component::main_query_field_name_id,$local_parameter->component_id);
                    if (($local_index > -1) &&
                        ($this->main_query_parameter->sql_values[t_cuteengine_component::main_query_field_name_show_on_page] == self::show_on_page_only_if_requested_and_sole_component))
                    {
                        $this->sole_component_id = $this->main_query_parameter->sql_values[t_cuteengine_component::main_query_field_name_id];
                        $this->main_query_parameter->first();
                    }
                    
                }
                
            }   
            return ($this->sole_component_id !== null);    
        }  
		
		// G
		public function generate_temporary_page_script($a_msg)
		{
            global $g_database_namespace;
            
			$local_main_tag = new t_base_tag(t_base_tag_type::btt_doctype,'doctype');
			//<html lang="it" xml:lang="it" xmlns="http://www.w3.org/1999/xhtml">
			$local_html_tag = $local_main_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_html,'html');
			$local_html_tag->add_property('lang','it');
			$local_html_tag->add_property('xml:lang','it');
			$local_html_tag->add_property('xmlns','http://www.w3.org/1999/xhtml');
			//<head>
			$local_head_tag = $local_html_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_head,'head');
			// <title>
			$local_title_tag = $local_head_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_title,'title');
			$local_title_tag->include_child_str = true;
			$local_title_tag->set_text_to_include('Workly.it | Lavoro Operaio,  offerte lavoro');
			//<body>
			$local_body_tag = $local_html_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_body,'body');
            // javascript google_analytics_script
			if ($g_database_namespace->google_analytics_enable)
			{
				$local_html_tag->add_text_to_include_by_name('body','<script type="text/javascript">' . $g_database_namespace->google_analytics_script . '</script>');
            }
			//<p>
			$local_current_tag = $local_body_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_p,'p_msg');
            $local_current_tag->include_child_str = true;
			return $local_main_tag->generate_html_code($a_msg);
		}
		public function get_cuteengine_component_by_id($a_id)
		{
			return $this->components[$a_id][self::components_cuteengine_component];
		}
        public function get_childs_list($a_component_id)
		{
			$local_level_no = $this->temporary_processed_component_list[$a_component_id];
            $local_childs_list = $this->page_structure_array[$a_level_no][$a_component_id];
            return $local_childs_list;
            
		}
		public function get_processed_component_level($a_component_id)
		{
			return $this->temporary_processed_component_list[$a_component_id];
            
		}	
		public function display_processed_component($a_component_id)
		{
			$local_level = $this->temporary_processed_component_list[$a_component_id];
            //echo "local_level: $local_level<br>";
			return $this->display_component($a_component_id,$local_level);
		}
		
		// L
		public function load_configuration_from_db()
		{
		
            //  
		
            $this->add_all_CEC();
			

			//echo "this->site_name $this->site_name - " ;
			//echo "this->enabled $this->enabled";
			//$this->enabled;
		}
		// S
		public function set_current_session($a_session)
		{
			global $g_javascript_namespace;
			$this->current_session = $a_session;
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
				get_class($this),'current_session',"'$a_session'");
		}
		public function set_header_property_to_page($a_root_component_id,$a_style_sheet_script)
        {
            $local_root_component = $this->components[$a_root_component_id][self::components_cuteengine_component];
            $local_root_component->set_header_property_to_page($a_style_sheet_script);
        }
        public function set_javascript_functions_to_page($a_root_component_id,$a_javascript_functions_script)
        {
            $local_root_component = $this->components[$a_root_component_id][self::components_cuteengine_component];
            $local_root_component->set_javascript_functions_to_page($a_javascript_functions_script);
        }
        public function set_url_parameter($a_component_id,$a_url_parameter)
        {
            $local_component = $this->components[$a_component_id][self::components_cuteengine_component];
            $local_component->set_url_parameter($a_url_parameter);
        }
		
	}
?>